package equipement;

import java.util.ArrayList;

public class Equipement {
	
	private Arme armeR;
	private Arme armeL;
	private Armure armure;
	private ArrayList<Objet> sacADos;
	
	public Equipement ()
	{
		this.armeR = new Arme(EArme.Poing);
		this.armeL = null;
		this.armure = new Armure(EArmure.Tunique);
		this.sacADos = new ArrayList<Objet>();
	}
	
	public void SetEquipement (EArme armeR, EArme armeL, EArmure armure, 
								ArrayList<Objet> sacADos, int[] carac)
	{
		setArmeR(armeR, carac);
		setArmeL(armeL, carac);
		setArmure(armure);
		if(sacADos != null)
			this.sacADos = sacADos;
	}
		
	public Arme getArmeR() {
		return armeR;
	}

	public void setArmeR(EArme armeR, int[] carac) {
		if(armeR!=null)
			this.armeR = new Arme(armeR, carac);
		else
			this.armeR = new Arme(EArme.Poing, carac);
	}

	public Arme getArmeL() {
		return armeL;
	}

	public void setArmeL(EArme armeL, int[] carac) {
		if(armeL!=null)
			this.armeL = new Arme(armeL, carac);
		else
			this.armeL = null;
	}

	public Armure getArmure() {
		return armure;
	}

	public void setArmure(EArmure armure) {
		if(armure!=null)
			this.armure = new Armure(armure);
		else
			this.armure = new Armure(EArmure.Tunique);
	}

	public void AddSacADos(EArmure armure){
		this.sacADos.add(new Armure(armure));
	}
	
	public void AddSacADos(EArme arme){
		this.sacADos.add(new Arme(arme));
	}
	
	public void AddSacADos(EMateriel materiel){
		this.sacADos.add(new Materiel(materiel));
	}
	
	public boolean DeleteSacADos (EArmure armure) {
		boolean res = false;
		Armure objet;
		int i;
	
		for(i=0 ; i<this.sacADos.size() ; i++) {
			if(this.sacADos.get(i).getClass() == Armure.class) {
				objet = (Armure)(this.sacADos.get(i));
				if (objet.getArmure() == armure) {
					this.sacADos.remove(i);
					i = this.sacADos.size();
					res = true;
				}
			}
		}
		
		return res;
	}
	
	public boolean DeleteSacADos (EArme arme) {
		boolean res = false;
		Arme objet;
		int i;
	
		for(i=0 ; i<this.sacADos.size() ; i++) {
			if(this.sacADos.get(i).getClass() == Arme.class) {
				objet = (Arme)(this.sacADos.get(i));
				if (objet.getArme() == arme) {
					this.sacADos.remove(i);
					i = this.sacADos.size();
					res = true;
				}
			}
		}
		
		return res;
			
	}
		
	public boolean DeleteSacADos (EMateriel materiel) {
		boolean res = false;
		Materiel objet;
		int i;
	
		for(i=0 ; i<this.sacADos.size() ; i++) {
			if(this.sacADos.get(i).getClass() == Materiel.class) {
				objet = (Materiel)(this.sacADos.get(i));
				if (objet.getMateriel() == materiel) {
					this.sacADos.remove(i);
					i = this.sacADos.size();
					res = true;
				}
			}
		}
		
		return res;
		
	}
	
	public String toString(){
		int i;
		String res = "Main droite : " + this.armeR;
		
		if(this.armeL != null)
			res = res + "\nMain gauche : " + this.armeL;
		else
			res = res + "\nMain gauche : rien";
		
		res = res + "\nArmure : " + this.armure;
		
		res = res + "\nSAC A DOS :";
		if(!this.sacADos.isEmpty()){
			for(i=0; i<this.sacADos.size(); i++)
				res = res + "\n" + this.sacADos.get(i);
		}
		else
			res = res + " vide";
		
		return res;
	}
	
}
